﻿using RayDen.Library.Core;
using RayDen.Library.Core.Primitives;

namespace RayDen.RayEngine.Data.Surface
{
    public struct ComponentProbabilities
    {
        public float diffProb;
        public float glossProb;
        public float reflProb;
        public float refrProb;
    };


    public enum BsdfEvents : byte
    {
        kNONE = 0,
        kDiffuse = 1,
        kPhong = 2,
        kReflect = 4,
        kRefract = 8,
        kSpecular = (kReflect | kRefract),
        kNonSpecular = (kDiffuse | kPhong),
        kAll = (kSpecular | kNonSpecular)
    }


    public class BSDF
    {

        public BSDF(int mID = -1)
        {
            this.mMaterialID = mID;
        }

        int mMaterialID;       //!< Id of scene material, < 0 ~ invalid
        ONB mFrame;            //!< Local frame of reference
        Vector mLocalDirFix;      //!< Incoming (fixed) direction, in local
        bool mIsDelta;          //!< True when material is purely specular
        ComponentProbabilities mProbabilities; //!< Sampling probabilities
        float mContinuationProb; //!< Russian roulette probability
        float mReflectCoeff;     //!< Fresnel reflection coefficient (for glass) 
        /*
        void Setup(
        ref  IRay   aRay,
        const Isect &aIsect,
        const Scene &aScene)
    {
        mMaterialID = -1;
        mFrame.SetFromZ(aIsect.normal);
        mLocalDirFix = mFrame.ToLocal(-aRay.dir);

        // reject rays that are too parallel with tangent plane
        if(std::abs(mLocalDirFix.z) < EPS_COSINE)
        {
            return;
        }

        const Material &mat = aScene.GetMaterial(aIsect.matID);
        GetComponentProbabilities(mat, mProbabilities);

        mIsDelta = (mProbabilities.diffProb == 0) && (mProbabilities.phongProb == 0);

        // now it becomes valid
        mMaterialID = aIsect.matID;
    }*/
    }
}